home *** CD-ROM | disk | FTP | other *** search
/ Best Tools for JAVA / Best Tools for JAVA.iso / POSTSCPT / GSVIEW / SRC / GVPMISC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-17  |  5.3 KB  |  224 lines

  1. /* Copyright (C) 1993, 1994, Russell Lang.  All rights reserved.
  2.   
  3.   This file is part of GSview.
  4.   
  5.   This program is distributed with NO WARRANTY OF ANY KIND.  No author
  6.   or distributor accepts any responsibility for the consequences of using it,
  7.   or for whether it serves any particular purpose or works at all, unless he
  8.   or she says so in writing.  Refer to the GSview Free Public Licence 
  9.   (the "Licence") for full details.
  10.   
  11.   Every copy of GSview must include a copy of the Licence, normally in a 
  12.   plain ASCII text file named LICENCE.  The Licence grants you the right 
  13.   to copy, modify and redistribute GSview, but only under certain conditions 
  14.   described in the Licence.  Among other things, the Licence requires that 
  15.   the copyright notice and this notice be preserved on all copies.
  16. */
  17.  
  18. /* gvpmisc.c */
  19. /* Miscellaneous PM GSview routines */
  20.  
  21. #include "gvpm.h"
  22.  
  23. BOOL
  24. SetDlgItemText(HWND hwnd, int id, char *str)
  25. {
  26.     WinSetWindowText(WinWindowFromID(hwnd, id), str);
  27.     return TRUE;
  28. }
  29.  
  30. void
  31. post_close(void)
  32. {
  33.     WinPostMsg(hwnd_bmp, WM_CLOSE, MPFROMLONG(0), MPFROMLONG(0));
  34. }
  35.  
  36. void
  37. get_help()
  38. {
  39.     WinPostMsg(hwnd_frame, WM_HELP,
  40.     MPFROMLONG(0), MPFROM2SHORT(CMDSRC_OTHER, FALSE));
  41. }
  42.  
  43. /* display message */
  44. int
  45. message_box(char *str, int icon)
  46. {
  47.       return WinMessageBox(HWND_DESKTOP, hwnd_frame ? hwnd_frame : HWND_DESKTOP, 
  48.         str, szAppName, 0, icon | MB_MOVEABLE | MB_OK);
  49. }
  50.  
  51. /* change menu item checkmark */
  52. void
  53. check_menu_item(int menuid, int itemid, BOOL checked)
  54. {
  55. HWND hwndMenu;
  56. MENUITEM mi;
  57.     hwndMenu = WinWindowFromID(hwnd_frame, FID_MENU);
  58.     WinSendMsg(hwndMenu, MM_QUERYITEM, 
  59.         MPFROM2SHORT(menuid, TRUE), MPFROMP(&mi));
  60.     WinSendMsg(mi.hwndSubMenu, MM_SETITEMATTR, MPFROMLONG(itemid),
  61.         MPFROM2SHORT(MIA_CHECKED, checked ? MIA_CHECKED : 0));
  62. }
  63.  
  64. /* get text of menu item */
  65. int
  66. get_menu_string(int menuid, int itemid, char *str, int len)
  67. {
  68. HWND hwndMenu;
  69. MENUITEM mi;
  70.     hwndMenu = WinWindowFromID(hwnd_frame, FID_MENU);
  71.     WinSendMsg(hwndMenu, MM_QUERYITEM, 
  72.         MPFROM2SHORT(menuid, TRUE), MPFROMP(&mi));
  73.     return (int)WinSendMsg(mi.hwndSubMenu, MM_QUERYITEMTEXT, 
  74.         MPFROM2SHORT(itemid, len), MPFROMP(str));
  75. }
  76.  
  77. int
  78. load_string(int id, char *str, int len)
  79. {
  80.     return WinLoadString(hab, 0, id, len, str);
  81. }
  82.  
  83.  
  84. void
  85. play_system_sound(char *id)
  86. {
  87. HINI hini;
  88. char buf[MAXSTR];
  89. char *p;
  90.     if ( (hini = PrfOpenProfile(hab, szMMini)) == NULLHANDLE )
  91.         return;
  92.     PrfQueryProfileString(hini, "MMPM2_AlarmSounds", id, "##", buf, sizeof(buf));
  93.     PrfCloseProfile(hini);
  94.         p = strchr(buf,'#');
  95.         if (p != (char *)NULL) {
  96.         *p = '\0';
  97.         (*pfnMciPlayFile)(hwnd_frame, buf, 0, 0, 0);
  98.     }
  99.     return;
  100. }
  101.  
  102. void
  103. play_sound(int num)
  104. {
  105. ULONG rc;
  106.     if (strlen(sound[num].file)==0)
  107.         return;
  108.     if (!(pfnMciPlayFile) || (strcmp(sound[num].file,BEEP)==0)) {
  109.         DosBeep(200,200);
  110.         return;
  111.     }
  112.     if (isdigit(*sound[num].file))
  113.         play_system_sound(sound[num].file);
  114.     else {
  115.         char buf[MAXSTR];
  116.         buf[0] = '\042';
  117.         strcpy(buf+1, sound[num].file);
  118.         strcat(buf, "\042");
  119.         if ((*pfnMciPlayFile)(hwnd_frame, buf, 0, 0, 0))
  120.             DosBeep(200,200);
  121.     }
  122. }
  123.  
  124.  
  125.  
  126. void
  127. info_wait(int id)
  128. {
  129. POINTL pt, pt_save;
  130. RECTL rect;
  131.     if (id)
  132.         load_string(id, szWait, sizeof(szWait));  /* revert to generic text */
  133.     else
  134.         szWait[0] = '\0';
  135.  
  136.     if (hwnd_status) {
  137.         WinInvalidateRect(hwnd_status, (PRECTL)NULL, TRUE);
  138.           WinUpdateWindow(hwnd_status);
  139.     }
  140.     /* find out if cursor over hwnd_bmp */
  141.     if (!WinQueryPointerPos(HWND_DESKTOP, &pt))
  142.         return;
  143.     if (hwnd_bmp == WinWindowFromPoint(HWND_DESKTOP, &pt, TRUE))
  144.         WinSendMsg(hwnd_bmp, WM_MOUSEMOVE, MPFROM2SHORT(pt.x, pt.y), (MPARAM)0);
  145. }
  146.  
  147.  
  148. int 
  149. gs_chdir(char *dirname)
  150. {
  151. #ifdef __BORLANDC__
  152.     if (isalpha(dirname[0]) && (dirname[1]==':'))
  153.         (void) setdisk(toupper(dirname[0])-'A');
  154.     if (!((strlen(dirname)==2) && isalpha(dirname[0]) && (dirname[1]==':')))
  155.         chdir(dirname);
  156.     return TRUE;
  157. #else
  158.     if (isalpha(dirname[0]) && (dirname[1]==':'))
  159.         if (_chdrive(dirname[0]))
  160.         return -1;
  161.     return _chdir2(dirname);
  162. #endif
  163. }
  164.  
  165. char * 
  166. gs_getcwd(char *dirname, int size)
  167. {
  168. #ifdef __BORLANDC__
  169.     return getcwd(dirname, size);
  170. #else
  171.     return _getcwd2(dirname, size);
  172. #endif
  173. }
  174.  
  175.  
  176. void
  177. send_prolog(FILE *f, int resource)
  178. {  
  179. char *prolog, *p;
  180. APIRET rc;
  181.     rc = DosGetResource(0, RT_RCDATA, resource, (PPVOID)&prolog);
  182.     if (!rc && (prolog != (char *)NULL) ) {
  183.         p = prolog;
  184.         while (*p) {
  185.             while (*p) {
  186.             if (debug_file != (FILE *)NULL)
  187.                     fputc(*p, debug_file);
  188.                 fputc(*p++, f);
  189.         }
  190.         p++;    /* skip end of string null */
  191.         }
  192.         DosFreeResource(prolog);
  193.     }
  194. }
  195.  
  196. char tempbuf[8192];
  197.  
  198. void
  199. profile_create_section(PROFILE *prf, char *section, int id)
  200. {
  201. char *rcdata, *entry, *value;
  202. char name[MAXSTR];
  203.     if (!DosGetResource(0, RT_RCDATA, id, (PPVOID)&rcdata)) {
  204.     if (rcdata == (char *)NULL) {
  205.         profile_close(prf);
  206.         return;
  207.     }
  208.     entry = rcdata;
  209.     while (strlen(entry)!=0) {
  210.         for ( value = entry; 
  211.           (*value!='\0') && (*value!=',') && (*value!='='); 
  212.           value++)
  213.         /* nothing */;
  214.         strncpy(name, entry, value-entry);
  215.         name[value-entry] = '\0';
  216.         value++;
  217.         profile_write_string(prf, section, name, value);
  218.         entry = value + strlen(value) + 1;
  219.     }
  220.    }
  221.    DosFreeResource(rcdata);
  222. }
  223.  
  224.